package org.fullhappy.model;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hiep
 */
public class FileUpload {
    String name;
    byte[] content;
    String realDirectory;

    public void saveFile() {
        File file = null;
        String fileName = "";
        OutputStream out = null;
        do {
            fileName = System.currentTimeMillis() + "_" + name;
            file = new File(realDirectory, fileName);
        } while (file.exists());
        this.setName(fileName);
        try {
            file.createNewFile();
            out = new FileOutputStream(file);
            out.write(content, 0, content.length);            
        } catch (Exception ex) {
            Logger.getLogger(MusicModel.class.getName()).log(Level.SEVERE, null, ex);
        }
        name= fileName;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte[] getContent() {
        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    public String getRealDirectory() {
        return realDirectory;
    }

    public void setRealDirectory(String realDirectory) {
        this.realDirectory = realDirectory;
    }
   
}
